const time = {
  // 日期转为2020-20-20的格式
  dateToFormal(date, seperator) {
    let year = date.getFullYear()
    let month = date.getMonth() + 1
    let day = date.getDate()
    if (month <= 9) {
      month = '0' + month
    }
    if (day <= 9) {
      day = '0' + day
    }
    let currentdate = year + seperator + month + seperator + day;
    return currentdate;
  },
  //获取当前的日期（2020-20-20的格式）
  getCurrentDay() {
    let date = new Date()
    let seperator = "-";
    return this.dateToFormal(date, seperator)
  },
  // 获取某day之前/之后somedays的日期
  getSomeDay(day, somedays) {
    let date = new Date(day)
    let temp = date.getTime() + 1000 * 60 * 60 * 24 * somedays
    let result = new Date(temp)
    return this.dateToFormal(result, '-')
  },
  //判断时间段是否有重叠(09:00),
  // timeList现在已有的时间列表，timeA起始时间，timeB结束时间
  isTimeOverlap(timeList, timeA, timeB) {
    if (timeList.length === 0) {
      return true
    }
    timeList.forEach(element => {
      if (
        !(
          // 比较起始时间和截止时间,A<B返回-1，A=B返回0，A>B返回1
          (
            this.compareTime(timeB, element.startTime) < 1 ||
            this.compareTime(timeA, element.endTime) > -1
          )
        )
      ) {
        flag = false;
      }
    });
    return true
  },
  //比较两个时间的大小，更早的时间就更小
  compareTime(timeA, timeB) {
    let hour_a = timeA.substring(0, 2);
    let minute_a = timeA.substring(3, 5);
    let hour_b = timeB.substring(0, 2);
    let minute_b = timeB.substring(3, 5);
    if (hour_a < hour_b) {
      return -1;
    } else if (hour_a > hour_b) {
      return 1;
    } else if (hour_b === hour_a) {
      if (minute_a < minute_b) {
        return -1;
      } else if (minute_a > minute_b) {
        return 1;
      } else {
        return 0;
      }
    }
  },
  //1，2，3，4，5，6，7转为对应的星期
  weekToNumber(remindDays) {
    if (remindDays === undefined) {
      return null
    }
    let result = "";
    for (let i = 0; i < remindDays.length; ++i) {
      if (remindDays[i] !== null) {
        let temp;
        switch (remindDays[i]) {
          case 'MON':
          case '周一':
            temp = 1;
            break;
          case 'TUE':
          case '周二':
            temp = 2;
            break;
          case 'WED':
          case '周三':
            temp = 3;
            break;
          case 'THU':
          case '周四':
            temp = 4;
            break;
          case 'FRI':
          case '周五':
            temp = 5;
            break;
          case 'SAT':
          case '周六':
            temp = 6;
            break;
          case 'SUN':
          case '周日':
            temp = 7;
            break;
          default:
            temp = remindDays[i]
        }
        result = result + temp + "  ";
      }
    }
    return result;
  },
  weekToChineses(remindDays) {
    if (remindDays === undefined) {
      return null
    }
    let result = "";
    for (let i = 0; i < remindDays.length; ++i) {
      if (remindDays[i] !== null) {
        let temp;
        switch (remindDays[i]) {
          case 'MON':
          case 1:
            temp = "周一";
            break;
          case 'TUE':
          case 2:
            temp = "周二";
            break;
          case 'WED':
          case 3:
            temp = "周三";
            break;
          case 'THU':
          case 4:
            temp = "周四";
            break;
          case 'FRI':
          case 5:
            temp = "周五";
            break;
          case 'SAT':
          case 6:
            temp = "周六";
            break;
          case 'SUN':
          case 7:
            temp = "周日";
            break;
          default:
            temp = remindDays[i]
        }
        result = result + temp + "  ";
      }
    }
    return result;
  },
  //1,2,3转为MON,TUE
  weekToEnglish(remindDays) {
    if (remindDays === undefined) {
      return null
    }
    let result = [];
    for (let i = 0; i < remindDays.length; ++i) {
      if (remindDays[i] !== null) {
        let temp
        switch (remindDays[i]) {
          case '周一':
          case 1:
            temp = "MON";
            break;
          case '周二':
          case 2:
            temp = "TUE";
            break;
          case '周三':
          case 3:
            temp = "WED";
            break;
          case '周四':
          case 4:
            temp = "THU";
            break;
          case '周五':
          case 5:
            temp = "FRI";
            break;
          case '周六':
          case 6:
            temp = "SAT";
            break;
          case '周日':
          case 7:
            temp = "SUN";
            break;
          default:
            temp = remindDays[i]
        }
        result[i] = temp
      }
    }
    return result;
  },
}
export default time